﻿using System;
using CommonUtils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebUtils.Core;

namespace plasp.cookiea.com.Controllers
{
    public class LoginAuthController : RedirectHelper
    {
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="psd"></param>
        /// <returns></returns>
        // GET: LoginAuth
        public ActionResult Login(string username, string pwd)
        {
            if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(pwd))
                throw new Exception("请输入用户名与密码");

            var token = $"Jwt:{username}{pwd}";
            HttpContext.Session.SetString(StaticString.Token, token);

            HttpContext.Response.Cookies.Append(StaticString.Token, token, new CookieOptions
            {
                Expires = DateTime.Now.AddMinutes(30)
            });

            return Json(new {Success = true});
        }
    }
}
